package gui;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.border.BevelBorder;


import com.framework.gui.EditorPanel;
import com.framework.gui.GuiUtilities;

import java.awt.Rectangle;
import java.util.Collections;

public class MantenimientoCamiones extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JScrollPane tablaCamionesjScrollPane = null;
	private JTable tablaCamionesjTable = null;
	private JButton agregarjButton = null;
	private JButton editarjButton = null;
	private JButton eliminarjButton = null;

	/**
	 * This is the default constructor
	 */
	public MantenimientoCamiones() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(800, 600);
		this.setContentPane(getJContentPane());
		this.setTitle("ngCAM ::: Mantenimiento de camiones");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getTablaCamionesjScrollPane(), null);
			jContentPane.add(getAgregarjButton(), null);
			jContentPane.add(getEditarjButton(), null);
			jContentPane.add(getEliminarjButton(), null);
			jContentPane.add(getTablaCamionesjTable(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes tablaCamionesjScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getTablaCamionesjScrollPane() {
		if (tablaCamionesjScrollPane == null) {
			tablaCamionesjScrollPane = new JScrollPane();
			tablaCamionesjScrollPane.setViewportBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
		}
		return tablaCamionesjScrollPane;
	}

	/**
	 * This method initializes tablaCamionesjTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getTablaCamionesjTable() {
		if (tablaCamionesjTable == null) {
			tablaCamionesjTable = new JTable();
			tablaCamionesjTable.setShowGrid(true);
			tablaCamionesjTable.setBounds(new Rectangle(169, 6, 453, 419));
		}
		return tablaCamionesjTable;
	}

	/**
	 * This method initializes agregarjButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getAgregarjButton() {
		if (agregarjButton == null) {
			agregarjButton = new JButton();
			agregarjButton.setBounds(new Rectangle(674, 33, 97, 29));
			agregarjButton.setText("Agregar");
			agregarjButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
				}
			});
		}
		return agregarjButton;
	}

	/**
	 * This method initializes editarjButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getEditarjButton() {
		if (editarjButton == null) {
			editarjButton = new JButton();
			editarjButton.setBounds(new Rectangle(674, 74, 97, 29));
			editarjButton.setText("Editar");
		}
		return editarjButton;
	}

	/**
	 * This method initializes eliminarjButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getEliminarjButton() {
		if (eliminarjButton == null) {
			eliminarjButton = new JButton();
			eliminarjButton.setBounds(new Rectangle(674, 115, 97, 29));
			eliminarjButton.setText("Eliminar");
		}
		return eliminarjButton;
	}

	private void abrirAgregarCamionEditorPanel(){
		CamionEditorPanel panel = new CamionEditorPanel();
		panel.setMode(EditorPanel.NEW_MODE);
		panel.setUsuario(null);
		JDialog dialog = new JDialog(getParentFrame(), "Nuevo Usuario");
		dialog.setSize(panel.getSize());
		dialog.setModal(true);
		dialog.getContentPane().add(panel);
		GuiUtilities.centerWindow(dialog);
		dialog.setVisible(true);
		
		if(panel.getModalResult() == EditorPanel.MODAL_RESULT_OK){
			usuarios.add(panel.getUsuario());
			Collections.sort(usuarios);
			usuariosModel.fireTableDataChanged();
		}
		
	}
	
}
